package com.heima.controller;

import com.heima.pojo.GoodsInfo;
import com.heima.pojo.GoodsQueryParam;
import com.heima.pojo.PageBean;
import com.heima.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/vm-service/sku")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @PostMapping
    @ApiOperation("添加商品")
    public Boolean addGoods(@RequestBody GoodsInfo info) {
        log.info("要添加的信息为:{}", info);
        return goodsService.addGoods(info);
    }

    @GetMapping("/search")
    @ApiOperation("分页查询")
    public PageBean queryGoods(GoodsQueryParam goodsQueryParam) {
        log.info("要查询的起始数，商品总页数,可选goodsName 为：{}", goodsQueryParam);
        PageBean pageBean = goodsService.Goodslist(goodsQueryParam);
        return pageBean;
    }
    @PutMapping("/{skuId}")
    @ApiOperation("修改商品")
    public Boolean updateGoods(@RequestBody GoodsInfo goodsInfo,@PathVariable String skuId){
        log.info("要修改的内容和id为{},{}",goodsInfo,skuId);
        return goodsService.upDateGoods(goodsInfo,skuId);
    }

}
